
keep if  ( index>=-16 & index<=16 ) & ivsample==1

capture frame drop results
frame create results str10 outcomevar evicted notevicted time

foreach var of varlist anymental numnonpreg numED {

reg `var' evictionorder qdum2-qdum33 evictXq2-evictXq33 i.courttime i.courtq
		
*Calculate omitted group baseline mean
sum `var' if evictionorder==0 & index==-16  & e(sample)==1
local basemean=r(mean)
		
* adding period 1 (first) estimates
local rel_q=1-17
local qplot=`rel_q' 
local noevictplot= `basemean'
local evictplot=`basemean'+ _b[evictionorder] 
frame post results ("`var'")  (`evictplot') (`noevictplot') (`qplot')
		
foreach num of numlist 2(1)33 {
			local rel_q=`num'-17
			local qplot=`rel_q' 
			local noevictplot= `basemean'+_b[qdum`num']
			local evictplot=`basemean'+ _b[evictionorder]+_b[qdum`num']+_b[evictXq`num'] 
			frame post results ("`var'")  (`evictplot') (`noevictplot') (`qplot')
}
		
}

replace outcomevar="Num Mental Health" if regexm(outcome, "anymental")==1
replace outcomevar="Num Hospital Visits" if regexm(outcome, "numnonpreg")==1
replace outcomevar="Num Emergency Visits" if regexm(outcome, "numED")==1

frame results: save  ${Inputs}\NY_hospital_eventstudy, replace
